;
(function () {
'use strict';
/**
 * user 吴尧
 * @ngdoc function
 * @name sasdApp.factory:InfoViewService
 * @description 用户管理控制器
 * factory of the sasApp
 */
angular.module('services.faultLocation.pbossOm', [])
  .factory('pbossOmServer', ['Restangular', 'requeststate', 'reponsestate','$filter', pbossOmServer])
  .factory('requeststate', requeststate)
  .factory('reponsestate', reponsestate)
  .factory('productDataStores',productDataStores);

function pbossOmServer(Restangular, requeststate, reponsestate,$filter) {
  return {
    queryPbossBusiness: function(params, callback) {
      Restangular.all('sas/OMdisplay/PBossOM/businessReportAnalysis/businessDetail').post(params).then(callback);
    },
    //用户状态查询
    queryUserState: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/state').get().then(callback);
    },
    //用户状态统计
    queryUserData: function(params, callback) {
      Restangular.all('sas/OMdisplay/PBossOM/businessReportAnalysis/userState').post(params).then(callback);
    },
    //工单等级
    queryOrderLevel: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/workOrderLevel').get().then(callback);
    },
    //工单状态
    queryOrderState: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/workOrderState').get().then(callback);
    },
    //工单类别
    queryOrderType: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/workOrderType').get().then(callback);
    },
    //服务开通统计
    queryServiceOpen: function(params, callback) {
      Restangular.all('sas/OMdisplay/PBossOM/businessReportAnalysis/serviceOpen').post(params).then(callback);
    },
    //产品管理分析
    queryProdoct: function(params, callback) {
      Restangular.all('sas/OMdisplay/PBossOM/businessReportAnalysis/productManagement').post(params).then(callback);
    },
    //行业下拉框
    queryIndustry: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/industry').get().then(callback);
    },
    //订购渠道
    queryChannel: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/orderChannel').get().then(callback);
    },
    //卡类型
    queryCardType: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/cardType').get().then(callback);
    },
    //用户类型
    queryUserType: function(callback) {
      Restangular.one('sas/OMdisplay/PBossOM/businessReportAnalysis/userType').get().then(callback);
    },
    //订购关系统计
    queryOrderRelation: function(params, callback) {
      Restangular.all('sas/OMdisplay/PBossOM/businessReportAnalysis/orderRelation').post(params).then(callback);
    },
    queryConsistency: function() {
      Restangular.all('sas/OMdisplay/PBossOM/dataConsistency').post(requeststate.consistencyAnalysis).then(
        function(res) {
          if (res.state === '10000') {
            reponsestate.consisten.data = res.data.pageData;
          }
          return reponsestate;
        }
      );
    },
    //超时交易统计
    querytradeType: function() {
      Restangular.all('sas/OMdisplay/PBossOM/systemTrade/timeout').post(requeststate.trading).then(
        function(res) {
          if (res.state === '10000') {
            reponsestate.trading.data = res.data.pageData;
          }
          return reponsestate;
        }
      )
    },
    querypbooss: function() {
      Restangular.all('sas/OMdisplay/PBossOM/systemTrade/PBOSS').post({}).then(
        function(res) {
          if (res.state === '10000') {
            reponsestate.pboss.data = res.data.pageData;
          }
          return reponsestate;
        }
      );
    },
    /**
     * 机器查询
     */
    robot: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.robot.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/machineCard').post(requestParam).then(callback);
    },
    CCID: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.ICCID.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/ICCIDutilization').post(requestParam).then(callback);
    },
    /**
     * 号码段查询
     */
    number: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.number.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/numDistribute').post(requestParam).then(callback);
    },
    numberMark: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.numberMark.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/numSection').post(requestParam).then(callback);
    },
    numberRecycle: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.numberRecycle.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/numUtilization').post(requestParam).then(callback);
    },
    /**
     * IMSSI查询
     */
    IMSSI: function(callback) {
      var requestParam = {};
      requestParam.provinceCodes = requeststate.formFormat(requeststate.IMSSI.province);
      Restangular.all('sas/OMdisplay/PBossOM/resourceManagement/IMSIutilization').post(requestParam).then(callback);
    }
  };
}

function requeststate() {
  return {
    consistencyAnalysis: {},
    trading: {
      startTime: new Date(),
      endTime: new Date()
    },
    pboss: {
      startTime:new Date(),
      endTime:new Date
    },
    robot: {
      province: [],
    },
    number: {
      province: []
    },
    numberMark: {
      province: []
    },
    numberRecycle: {
      province: []
    },
    IMSSI: {
      province: []
    },
    ICCID: {
      province: []
    },
    formFormat: formFormat,
  };

  function formFormat(arrayData) {
    if (is.array(arrayData) && arrayData.length > 0) {
      return arrayData.map(function(item) {
        return item.provinceCode
      });
    } else {
      return [];
    }
  }
}

function reponsestate() {
  return {
    consisten: {
      data: ''
    },
    trading: {
      data: ''
    },
    pboss: {
      data: ''
    },
    robot: {
      data: ''
    }
  };
}

function productDataStores(){
  var data  = {};
  return {
    data: data,
    setCodeInit: function(){
      data.productCode = [];
      data.productName = [];
      data.flag = false;
    }
  };
}
})();